'use strict';

const Controller = require('egg').Controller;

class TableController extends Controller {
  async createTable() {
    const {areaId, code, description, persons} = this.ctx.request.body;
    const result = await this.ctx.service.table.table.createTable(code,description,areaId,persons);
    if(result === 'success'){
        this.ctx.code = 200;
        this.ctx.body = 'success';
    }else{
        this.ctx.code = 300;
        this.ctx.body = 'error';
    }
  }

  async getTables(){
      const result = await this.ctx.service.table.table.tableList();
      this.ctx.code = 200;
      this.ctx.body = result;
  }

  async deleteTableById(){
      const tid = this.ctx.request.body.tid;
      const result = await this.ctx.service.table.table.deleteTable(tid);
      if(result){
          this.ctx.code = 200;
          this.ctx.body = 'success';
      }else{
          this.ctx.code = 300;
          this.ctx.body = 'error';
      }
  }
}

module.exports = TableController;
